import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:yp/Xwidgets/cache_image.dart';
import 'package:yp/config/config.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'logic.dart';
import 'state.dart';

class OrderGoodlistPage extends StatelessWidget {
  final OrderGoodlistLogic logic = Get.put(OrderGoodlistLogic());
  final OrderGoodlistState state = Get.find<OrderGoodlistLogic>().state;

  @override
  Widget build(BuildContext context) {
    state.goodsList = Get.arguments;
    print(state.goodsList);
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        backgroundColor: Config.mainColor,
        brightness: Brightness.light,
        iconTheme: IconThemeData(color: Colors.white),
        title: Text(
          "商品列表",
          style: TextStyle(color: Colors.white, fontSize: 32.sp),
        ),
        centerTitle: true,
        elevation: 0,
      ),
      body: GetBuilder<OrderGoodlistLogic>(builder: (logic) {
        return Column(
          children: [
            Expanded(
              child: ListView(shrinkWrap: true, primary: true, children: [
                Column(
                  children: [
                    //商品部分
                    Container(
                      color: Colors.white,
                      child: Column(
                        children: [
                          ListView.builder(
                            itemBuilder: (ctx, index) {
                              return Container(
                                padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 40.w),
                                decoration: BoxDecoration(
                                  border: Border(
                                    bottom: BorderSide(
                                      color: Color(0xfff0f0f0),
                                    ),
                                  ),
                                ),
                                child: Column(
                                  children: [
                                    Row(
                                      crossAxisAlignment: CrossAxisAlignment.center,
                                      mainAxisAlignment: MainAxisAlignment.start,
                                      children: [
                                        Container(width: 220.w, padding: EdgeInsets.only(right: 20.w), child: CachedImage(path: state.goodsList[index]["image_default_id"], width: 200.w, height: 200.w)),
                                        Expanded(
                                          child: Column(
                                            crossAxisAlignment: CrossAxisAlignment.start,
                                            mainAxisAlignment: MainAxisAlignment.start,
                                            children: [
                                              Container(
                                                height: 100.w,
                                                child: Text(
                                                  state.goodsList[index]["title"],
                                                  style: TextStyle(
                                                    color: Color(0xff333333),
                                                    fontSize: 28.w,
                                                  ),
                                                  maxLines: 2,
                                                  textAlign: TextAlign.start,
                                                  overflow: TextOverflow.ellipsis,
                                                ),
                                              ),
                                              SizedBox(
                                                height: 10.w,
                                              ),
                                              Container(
                                                width: 500.w,
                                                child: Row(
                                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Container(
                                                      height: 60.w,
                                                      child: RichText(
                                                        text: TextSpan(
                                                          children: [
                                                            TextSpan(
                                                              text:
                                                                  state.goodsList[index]["price"] is double?
                                                                  '赠品':'￥${state.goodsList[index]["price"]["price"]}'
                                                              ,
                                                              style: TextStyle(color: Config.mainColor, fontSize: 24.w),
                                                            ),
                                                          ],
                                                        ),
                                                      ),
                                                    ),
                                                    Container(
                                                      child: Text(
                                                        'x${state.goodsList[index]["quantity"]}',
                                                        style: TextStyle(
                                                          color: Color(0xff999999),
                                                          fontSize: 28.sp,
                                                        ),
                                                      ),
                                                    ),

                                                  ],
                                                ),
                                              ),
                                                  state.goodsList[index]["is_part_integral"] == 1
                                                  && (state.goodsList[index]["integral_exchange_desc"]!=null && state.goodsList[index]["integral_exchange_desc"]!='')
                                                        ? Container(
                                                    padding: EdgeInsets.all(5.w),
                                                            decoration: new BoxDecoration(border: new Border.all(color: Colors.orange, width: 0.5), borderRadius: new BorderRadius.circular((10.w))),
                                                            child: Text(
                                                              '${state.goodsList[index]["integral_exchange_desc"]}',
                                                              style: TextStyle(
                                                                color:  Colors.orange,
                                                                fontSize: 20.sp,
                                                              ),
                                                            ),
                                                          )
                                                        : SizedBox(),
                                            ],
                                          ),
                                        ),
                                      ],
                                    ),
                                  ],
                                ),
                              );
                            },
                            shrinkWrap: true,
                            physics: NeverScrollableScrollPhysics(),
                            itemCount: state.goodsList.length,
                          ),
                        ],
                      ),
                    ),
                  ],
                )
              ]),
            ),
          ],
        );
      }),
    );
  }
}
